/**
 * Copyright (C) 2010, 2011 Neofonie GmbH
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.dicode.analysis.demonstrator;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import eu.dicode.analysis.demonstrator.model.HomeCommand;
import eu.dicode.analysis.demonstrator.util.CommandPopulator;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

  private final CommandPopulator pop;

  public HomeController() throws IOException {
    this.pop = new CommandPopulator();
  }

  /**
   * Simply selects the home view to render by returning its name.
   */
  @RequestMapping(value = "/home", method = RequestMethod.GET)
  public String home(final Model model) {
    final HomeCommand homeCommand = new HomeCommand();
    this.pop.populate(homeCommand);
    model.addAttribute("homeCommand", homeCommand);
    return "home";
  }
}
